package presentacion;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AgregarTareaDialog extends javax.swing.JDialog {
	

	private static final long serialVersionUID = 7534550295651793213L;
	
	
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JButton botonCancelar;
	private JButton botonCrear;
	private JTextField textTiempo;
	private JTextField textNombreTarea;
	private JTextField textIDTarea;

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}


	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				AgregarTareaDialog inst = new AgregarTareaDialog(frame);
				inst.setVisible(true);
			}
		});
	}
	
	public AgregarTareaDialog(JFrame frame) {
		super(frame);
		initGUI();
	}
	
	private void initGUI() {
		try {
			this.setSize(388, 225);
			setLayout(null);
			this.setTitle("Crear Tarea");
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Nombre:");
				jLabel1.setBounds(31, 65, 88, 16);
				jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("ID:");
				jLabel2.setBounds(31, 31, 88, 16);
				jLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("Tiempo (min):");
				jLabel3.setBounds(31, 99, 88, 16);
				jLabel3.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			{
				textIDTarea = new JTextField();
				getContentPane().add(textIDTarea);
				textIDTarea.setBounds(131, 25, 203, 28);
			}
			{
				textNombreTarea = new JTextField();
				getContentPane().add(textNombreTarea);
				textNombreTarea.setBounds(131, 59, 203, 28);
			}
			{
				textTiempo = new JTextField();
				getContentPane().add(textTiempo);
				textTiempo.setBounds(131, 93, 203, 28);
			}
			{
				botonCrear = new JButton();
				getContentPane().add(botonCrear);
				botonCrear.setText("Crear");
				botonCrear.setBounds(106, 141, 82, 28);
				botonCrear.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						
						if(textNombreTarea.getText().isEmpty()){
							JOptionPane.showMessageDialog(AgregarTareaDialog.this, "El nombre de la tarea no puede ser vacio");
							return;
						}
						
						if(textIDTarea.getText().isEmpty()){
							JOptionPane.showMessageDialog(AgregarTareaDialog.this, "El identificador de la tarea no puede ser vacio");
							return;
						}
						
						if(textTiempo.getText().isEmpty()){
							JOptionPane.showMessageDialog(AgregarTareaDialog.this, "El tiempo de la tarea no puede ser vacio");
							return;
						}	
						
						try{							
							int tiempo = Integer.valueOf(textTiempo.getText());
							tiempoTarea = tiempo;
							
						}catch(NumberFormatException e){
							JOptionPane.showMessageDialog(AgregarTareaDialog.this, "El tiempo de la tarea debe ser un numero (minutos).");
							return;
						}
						
						nombreTarea = textNombreTarea.getText();
						idTarea = textIDTarea.getText();						
						
						dispose();
					}
				});
			}
			{
				botonCancelar = new JButton();
				getContentPane().add(botonCancelar);
				botonCancelar.setText("Cancelar");
				botonCancelar.setBounds(206, 141, 78, 28);
				botonCancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						canceled = true;
						dispose();
					}
				});
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	// CODIGO
	
	private String nombreTarea;
	private int tiempoTarea;
	private String idTarea;
	
	private boolean canceled = false;
	
	public String getNombreTarea() {
		return nombreTarea;
	}

	public void setNombreTarea(String nombreTarea) {
		this.nombreTarea = nombreTarea;
	}

	public int getTiempoTarea() {
		return tiempoTarea;
	}

	public void setTiempoTarea(int tiempoTarea) {
		this.tiempoTarea = tiempoTarea;
	}

	public String getIdTarea() {
		return idTarea;
	}

	public void setIdTarea(String idTarea) {
		this.idTarea = idTarea;
	}
	
	
	public boolean isCanceled() {
		return canceled;
	}
	

}
